package com.example.dbsample.util.spring;

import org.springframework.core.NamedThreadLocal;

public class AppIdContextHolderUtil {
    private static final ThreadLocal<String> APPID_SOURCE = new NamedThreadLocal<String>("ds-appId") {
        @Override
        protected String initialValue() {
            return "";
        }
    };

    private AppIdContextHolderUtil() {

    }

    /**
     * 设置当前业务线
     */
    public static void set(String appId) {
        APPID_SOURCE.set(appId);
    }

    /**
     * 获取当前业务线
     */
    public static String get() {
        return APPID_SOURCE.get();
    }

    /**
     * 强制清空本地线程
     */
    public static void clear() {
        APPID_SOURCE.remove();
    }
}
